import React from "react";

import chartsRoute from "./index";
import {lazyLoad} from "@/utils";


/**
 * @description 图表组件分配与装载
 */
interface IChartMap {
  chartOption: DV.IChart;
  actions?: any
}
export const ChartMap = ({chartOption, actions}: IChartMap) => {
  const type: string = chartOption.type || '';
  if (!chartsRoute[type] || !type) return <React.Fragment/>;
  const Chart: any = lazyLoad(chartsRoute[type].component)
  return <Chart {...chartOption} actions={actions} />
}

/**
 * @description 组件高级配置面板分配与装载
 */
export const ChartPanelMap = (props: any) => {
  const type = props.type;
  if (!chartsRoute[type] || !type) return <React.Fragment/>;
  const Panel: any = lazyLoad(chartsRoute[type].panelComponent);
  return <Panel
    key={props.uid}
    {...props}
  />
}

/**
 * 是否含有仪表盘组件
 * @param type
 */
export function hasPanelComponent(type: string): boolean {
  if(!chartsRoute[type]) return false;
  return chartsRoute[type].hasOwnProperty('panelComponent')
}


